import { User } from "@/api/interface";
import { UserState } from "@/redux/interface";
import * as types from "@/redux/mutation-types";

const initState = {
	userColumn: []
};

export default function user(state: UserState = initState, action: any) {
	if (action.type == types.SET_USER_COLUMN) {
		return {
			...state,
			userColumn: action.payload.map((item: User.UserInfo) => {
				return {
					...item,
					key: item.id
				};
			})
		};
	} else if (action.type == types.SET_USER_ROW) {
		return {
			...state,
			userColumn: state.userColumn.map((item: User.UserInfo) => {
				return item.id == action.payload.id ? action.payload : item;
			})
		};
	}
	return state;
}
